package com.example.springbootdemo.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.example.springbootdemo.entity.SpMovie;
import com.example.springbootdemo.mapper.SpMovieMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 影院售票-电影信息表-5 前端控制器
 * </p>
 *
 * @author 廖老师
 * @since 2023-11-24
 */
@RestController
@RequestMapping("/springbootdemo/spMovie")
public class SpMovieController {

    @Resource
    SpMovieMapper movieMapper;

    @GetMapping("queryMovie")
    public List<SpMovie> queryMovie(){
        // 查询全部
        return movieMapper.selectList(null);
    }

    @GetMapping("queryMovieByName")
    public List<SpMovie> queryMovie(String name){
        LambdaQueryWrapper<SpMovie> lqw = new LambdaQueryWrapper<>();
        // 生成条件 name = ?   eq => equals
        // lqw.eq(SpMovie::getName, name);
        // name like ?
        lqw.like(SpMovie::getName, name);
        // 查询全部
        return movieMapper.selectList(lqw);
    }

    // 组合条件查询
    @GetMapping("queryMovieByObject")
    public IPage queryMovie(SpMovie movie, int page, int size){
        LambdaQueryWrapper<SpMovie> lqw = new LambdaQueryWrapper<>();
        lqw.like(movie.getName()!=null, SpMovie::getName,
                movie.getName());
        lqw.eq(movie.getType()!=null , SpMovie::getType,
                movie.getType());
        // TODO
        // 分页查询  p 分页对象
        IPage p = new PageDTO(page, size);
        return movieMapper.selectPage(p, lqw);
    }
}

